package com.example.projectcode.controller.Admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.projectcode.model.Teacher;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "后台管理员管理老师端接口")
@RestController
@RequestMapping("/admin")
public class AdminTeachersController {

    @Autowired
    private TeacherService teacherService;



    /*----------------------教师个人信息管理------------------------------------------*/



    @ApiOperation(value = "新增老师")
    @PostMapping("/insertTeacher")
    public Result insertTeacher(@RequestBody Teacher teacher){
        boolean result = teacherService.insertTeacher(teacher);
        if (result){
            return Result.ok();
        }else {
            return Result.fail();
        }

    }


    @ApiOperation(value = "根据老师id删除老师")
    @DeleteMapping("/deleteTeacher/{id}")
    public Result deleteTeacher(@PathVariable Integer id){
        int result = teacherService.deleteTeacherById(id);
        if (result>0){
            return Result.ok();

        }else {
            return Result.fail();
        }
    }

    @PostMapping("/updateTeacher")
    @ApiOperation(value = "根据老师id修改老师信息")
    public Result updateTeacher(@RequestBody Teacher teacher){
        int result =  teacherService.updateTeacher(teacher);
        if (result>0){
            return Result.ok();
        }
        else {
            return Result.fail();
        }
    }

    @GetMapping("/queryAllTeachers/{page}/{size}")
    @ApiOperation(value = "分页查询所有老师")
    public Result queryAllStudents(@PathVariable long page,@PathVariable long size){
        Page<Teacher> page1 = new Page<>(page,size);
        IPage<Teacher> iPage = teacherService.page(page1,null);
        return Result.ok(iPage);
    }





}
